//
//  ConnectWechatViewController.m
//  ZYZB
//
//  Created by ENERGY on 2018/7/17.
//  Copyright © 2018年 ENERGY. All rights reserved.
//

#import "ConnectWechatViewController.h"
static int i = 59;

@interface ConnectWechatViewController ()<UITextFieldDelegate>
@property (nonatomic, strong)UITableView * tableView;
@property (nonatomic, strong)UIView * headerView;
@property (nonatomic, strong)UIImageView * wechatHeadImgView;//微信头像
@property (nonatomic, strong)UILabel * nameContentLab;//用户名
@property (nonatomic, strong)UITextField * phoneTextField;//手机
@property (nonatomic, strong)UITextField * verificationCodeField;//验证码
@property (nonatomic, strong)UITextField * inviteTextField;//邀请码
@property (nonatomic, strong)NSString * inviteCodeStr;//邀请码
@property (nonatomic, strong)UIButton * getVerificationCodeBtn;//获取验证码
@property (nonatomic, strong)NSString * telNumStr;//电话号码
@property (nonatomic, strong)NSTimer *timmer;
@property (nonatomic, strong)UITextField * codeTextField;//密码
@property (nonatomic, strong)UITextField * codeAgainTextField;//再次密码
@end

@implementation ConnectWechatViewController(networking)
//发送验证码
- (void)sendMessageCode{
    NSString * timeStr = [self currentTimeStr];
    //str
    NSDictionary * dic = @{@"phone":self.phoneTextField.text,
                           @"t":timeStr
                           };
    //sign
    NSDictionary * signDic = @{@"phone":self.phoneTextField.text,
                               @"t":timeStr,
                               @"merchantNo":@"80d709a97af1b8ab"
                               };
    SortMD5Code * md5Code = [[SortMD5Code alloc] init];
    NSString * jsonStr = [md5Code getJsonWithStrDic:dic withSignDic:signDic];
    NSData *postData = [jsonStr dataUsingEncoding:NSUTF8StringEncoding];
    NSURL *url = [NSURL URLWithString:@"http://120.78.157.132:82/index.php/sendCode/index?api=api1001"];
    NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:url];
    //设置请求方式
    request.HTTPMethod = @"POST";
    //设置请求参数
    request.HTTPBody = postData;
    [NSURLConnection sendAsynchronousRequest:request queue:[NSOperationQueue mainQueue] completionHandler:^(NSURLResponse * _Nullable response, NSData * _Nullable data, NSError * _Nullable connectionError) {
        [self hiddenProgressHUD];
        if (connectionError) {
            if (connectionError.code == -1001) {
                [self.view makeToast:@"请求网络超时，请稍后再试" duration:1 position:CSToastPositionCenter];
            }
        }else{
            NSDictionary *dictionary =[NSJSONSerialization JSONObjectWithData:data options:NSJSONReadingMutableLeaves error:nil];//data解析为dictionary
            if (!dictionary) {
                NSLog(@"数据缺失");
                return;
            }
        }
    }];
}

//关联账号
- (void)tiePhoneNum{
    NSString * timeStr = [self currentTimeStr];
    //邀请码
    self.inviteCodeStr = self.inviteTextField.text;
    if (self.inviteTextField.text == nil) {
        self.inviteCodeStr = @"";
    }
    //str
    NSDictionary * dic = @{
                           @"wxcode":self.wechatCodeString,
                           @"phone":self.phoneTextField.text,
                           @"yanzhengma":@"",
                           @"userPass":@"",
                           @"pass_again":@"",
                           @"invite_code":@"",
                           @"t":timeStr
                           };
    //sign
    NSDictionary * signDic = @{
                               @"wxcode":self.wechatCodeString,
                               @"phone":self.phoneTextField.text,
                               @"yanzhengma":@"",
                               @"userPass":@"",
                               @"pass_again":@"",
                               @"invite_code":@"",
                               @"t":timeStr,
                               @"merchantNo":@"80d709a97af1b8ab"
                               };
    SortMD5Code * md5Code = [[SortMD5Code alloc] init];
    NSString * jsonStr = [md5Code getJsonWithStrDic:dic withSignDic:signDic];
    NSData *postData = [jsonStr dataUsingEncoding:NSUTF8StringEncoding];
    NSURL *url = [NSURL URLWithString:@"http://120.78.157.132:82/index.php/sendCode/index?api=api1001"];
    NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:url];
    //设置请求方式
    request.HTTPMethod = @"POST";
    //设置请求参数
    request.HTTPBody = postData;
    [NSURLConnection sendAsynchronousRequest:request queue:[NSOperationQueue mainQueue] completionHandler:^(NSURLResponse * _Nullable response, NSData * _Nullable data, NSError * _Nullable connectionError) {
        [self hiddenProgressHUD];
        if (connectionError) {
            if (connectionError.code == -1001) {
                [self.view makeToast:@"请求网络超时，请稍后再试" duration:1 position:CSToastPositionCenter];
            }
        }else{
            NSDictionary *dictionary =[NSJSONSerialization JSONObjectWithData:data options:NSJSONReadingMutableLeaves error:nil];//data解析为dictionary
            if (!dictionary) {
                NSLog(@"数据缺失");
                return;
            }
            //        NSString * compareMD5Str = [md5Code encodeStringWithDictionary:dictionary];
            //        NSString * signResult = [dictionary objectForKey:@"sign"];//接到的json串sign字段
            //        NSDictionary * jsonData = [md5Code getNSDictionaryData:dictionary];//解析为字典数据
            //        if ([compareMD5Str isEqualToString:signResult]) {
            //            NSLog(@"成功");
            //        }else{
            //            NSLog(@"失败");
            //        }
        }
    }];
}

@end
@implementation ConnectWechatViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.view.backgroundColor = [UIColor whiteColor];
    self.navigationItem.title = @"关联微信";
    
//    [self setUpViews];
    [self.view addSubview:self.tableView];
}

- (UITableView *)tableView{
    if (!_tableView) {
        _tableView = [[UITableView alloc] initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT - BOTTOM_HEIGHT - NAVI_HEIGHT) style:UITableViewStylePlain];
        _tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
        _tableView.estimatedRowHeight = 100/WIDTH_6_SCALE;
        _tableView.rowHeight = UITableViewAutomaticDimension;
        _tableView.backgroundColor = [UIColor whiteColor];
        _tableView.tableHeaderView = self.headerView;
    }return _tableView;
}
- (UIView *)headerView{
    if (!_headerView) {
        _headerView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, 100/WIDTH_6_SCALE)];
        _headerView.backgroundColor = [UIColor whiteColor];
        //头像
        self.wechatHeadImgView = [[UIImageView alloc] init];
        self.wechatHeadImgView.frame = CGRectMake(0, 36/WIDTH_6_SCALE, 86/WIDTH_6_SCALE, 86/WIDTH_6_SCALE);
        self.wechatHeadImgView.centerX = self.view.centerX;
        self.wechatHeadImgView.image = [UIImage imageNamed:@"fulezhuyuan"];
        [_headerView addSubview:self.wechatHeadImgView];
        //用户名
        UILabel * nameTitleLab = [[UILabel alloc] initWithFrame:CGRectMake(48/WIDTH_6_SCALE, self.wechatHeadImgView.bottom + 41/WIDTH_6_SCALE, 130/WIDTH_6_SCALE, 13/WIDTH_6_SCALE)];
        [self label:nameTitleLab withFont:DEF_FontSize_12 withText:@"亲爱的福乐猪用户" withTextColor:[UIColor blackColor] withTextAlignment:NSTextAlignmentLeft withView:_headerView];
        self.nameContentLab = [[UILabel alloc] initWithFrame:CGRectMake(nameTitleLab.right, nameTitleLab.top, SCREEN_WIDTH - nameTitleLab.right - nameTitleLab.left, nameTitleLab.height)];
        [self label:self.nameContentLab withFont:DEF_FontSize_14 withText:@"" withTextColor:[UIColor blackColor] withTextAlignment:NSTextAlignmentLeft withView:_headerView];
        //说明
        UILabel * illustrateLab = [[UILabel alloc] initWithFrame:CGRectMake(nameTitleLab.left, nameTitleLab.bottom + 16/WIDTH_6_SCALE, SCREEN_WIDTH - nameTitleLab.left * 2, 28/WIDTH_6_SCALE)];
        [self label:illustrateLab withFont:DEF_FontSize_10 withText:@"为了让您更好的享受服务体验，请关联一个福乐猪账号" withTextColor:[UIColor blackColor] withTextAlignment:NSTextAlignmentLeft withView:_headerView];
        illustrateLab.lineBreakMode = 0;
        illustrateLab.numberOfLines = 0;
        //手机图案
        int phoneImgX = 50/WIDTH_6_SCALE;
        UIImageView * phoneImg = [[UIImageView alloc] initWithFrame:CGRectMake(phoneImgX, illustrateLab.bottom + 44/WIDTH_6_SCALE, 12/WIDTH_6_SCALE, 20/WIDTH_6_SCALE)];
        phoneImg.image = [UIImage imageNamed:@"phone"];
        [_headerView addSubview:phoneImg];
        //上面的输入框
        self.phoneTextField = [[UITextField alloc] initWithFrame:CGRectMake(phoneImg.right + 12/WIDTH_6_SCALE, 0, SCREEN_WIDTH - phoneImg.right - 12/WIDTH_6_SCALE - phoneImg.left, 22/WIDTH_6_SCALE)];
        self.phoneTextField.delegate = self;
        self.phoneTextField.centerY = phoneImg.centerY;
        self.phoneTextField.font = DEF_FontSize_12;
        self.phoneTextField.placeholder = @"请输入手机号码";
        self.phoneTextField.clearButtonMode = UITextFieldViewModeWhileEditing;
        [self.phoneTextField addTarget:self action:@selector(textFieldDidChange:) forControlEvents:UIControlEventEditingChanged];
        [_headerView addSubview:self.phoneTextField];
        //上面横线
        UIView * topLineView = [[UIView alloc] initWithFrame:CGRectMake(phoneImg.left, phoneImg.bottom + 8/WIDTH_6_SCALE, SCREEN_WIDTH - phoneImgX*2, 1/WIDTH_6_SCALE)];
        topLineView.backgroundColor = getColor(grayColor);
        [_headerView addSubview:topLineView];
        //锁头图案
        UIImageView * lockImg = [[UIImageView alloc] initWithFrame:CGRectMake(phoneImg.left, topLineView.bottom + 32/WIDTH_6_SCALE, 17.5/WIDTH_6_SCALE, 18/WIDTH_6_SCALE)];
        lockImg.centerX = phoneImg.centerX;
        lockImg.image = [UIImage imageNamed:@"verificationCode"];
        [_headerView addSubview:lockImg];
        //下面输入框
        self.verificationCodeField = [[UITextField alloc] initWithFrame:CGRectMake(self.phoneTextField.left, 0, self.phoneTextField.width, self.phoneTextField.height)];
        self.verificationCodeField.centerY = lockImg.centerY;
        self.verificationCodeField.delegate = self;
        self.verificationCodeField.font = DEF_FontSize_12;
        self.verificationCodeField.placeholder = @"请输入验证码";
        [_headerView addSubview:self.verificationCodeField];
        //获取验证码按钮
        int getVerificationCodeBtnW = 90/WIDTH_6_SCALE;
        self.getVerificationCodeBtn = [[UIButton alloc] initWithFrame:CGRectMake(self.phoneTextField.right - getVerificationCodeBtnW, 0, getVerificationCodeBtnW, 30/WIDTH_6_SCALE)];
        self.getVerificationCodeBtn.centerY = self.verificationCodeField.centerY;
        [self.getVerificationCodeBtn setTitle:@"获取验证码" forState:UIControlStateNormal];
        [self.getVerificationCodeBtn addTarget:self action:@selector(getVerificationCodeBtnClick:) forControlEvents:UIControlEventTouchUpInside];
        [self.getVerificationCodeBtn setBackgroundColor:[UIColor orangeColor]];
        [self button:self.getVerificationCodeBtn withBGColor:[UIColor orangeColor] withLayerBorderColor:nil withLayerBorderWith:0 withCornerRadius:6 withMasksToBounds:YES withViwe:self.view];
        [self.getVerificationCodeBtn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
        self.getVerificationCodeBtn.titleLabel.font = DEF_FontSize_12;
        [_headerView addSubview:self.getVerificationCodeBtn];
        //下面横线
        UIView * bottomLineView = [[UIView alloc] initWithFrame:CGRectMake(topLineView.left, lockImg.bottom + 8/WIDTH_6_SCALE, topLineView.width, topLineView.height)];
        bottomLineView.backgroundColor = getColor(grayColor);
        [_headerView addSubview:bottomLineView];
        //密码图案
        int codeImgX = 50/WIDTH_6_SCALE;
        UIImageView * codeImg = [[UIImageView alloc] initWithFrame:CGRectMake(codeImgX, bottomLineView.bottom + 44/WIDTH_6_SCALE, 16/WIDTH_6_SCALE, 18/WIDTH_6_SCALE)];
        codeImg.image = [UIImage imageNamed:@"code"];
        [_headerView addSubview:codeImg];
        //上面的输入框
        self.codeTextField = [[UITextField alloc] initWithFrame:CGRectMake(codeImg.right + 12/WIDTH_6_SCALE, 0, SCREEN_WIDTH - codeImg.right - 12/WIDTH_6_SCALE - codeImg.left, 22/WIDTH_6_SCALE)];
        self.codeTextField.delegate = self;
        self.codeTextField.centerY = codeImg.centerY;
        self.codeTextField.font = DEF_FontSize_12;
        self.codeTextField.placeholder = @"请输入密码";
        self.codeTextField.clearButtonMode = UITextFieldViewModeWhileEditing;
        [self.codeTextField addTarget:self action:@selector(textFieldDidChange:) forControlEvents:UIControlEventEditingChanged];
        [_headerView addSubview:self.codeTextField];
        //下面横线
        UIView * codeBottomLineView = [[UIView alloc] initWithFrame:CGRectMake(codeImg.left, codeImg.bottom + 8/WIDTH_6_SCALE, SCREEN_WIDTH - codeImgX*2, 1/WIDTH_6_SCALE)];
        codeBottomLineView.backgroundColor = getColor(grayColor);
        [_headerView addSubview:codeBottomLineView];
        //再次密码图案
        int codeAgainImgX = 50/WIDTH_6_SCALE;
        UIImageView * codeAgainImg = [[UIImageView alloc] initWithFrame:CGRectMake(codeAgainImgX, codeBottomLineView.bottom + 44/WIDTH_6_SCALE, 16/WIDTH_6_SCALE, 18/WIDTH_6_SCALE)];
        codeAgainImg.image = [UIImage imageNamed:@"code"];
        [_headerView addSubview:codeAgainImg];
        //上面的输入框
        self.codeAgainTextField = [[UITextField alloc] initWithFrame:CGRectMake(codeAgainImg.right + 12/WIDTH_6_SCALE, 0, SCREEN_WIDTH - codeAgainImg.right - 12/WIDTH_6_SCALE - codeAgainImg.left, 22/WIDTH_6_SCALE)];
        self.codeAgainTextField.delegate = self;
        self.codeAgainTextField.centerY = codeAgainImg.centerY;
        self.codeAgainTextField.font = DEF_FontSize_12;
        self.codeAgainTextField.placeholder = @"请再次输入密码";
        self.codeAgainTextField.clearButtonMode = UITextFieldViewModeWhileEditing;
        [self.codeAgainTextField addTarget:self action:@selector(textFieldDidChange:) forControlEvents:UIControlEventEditingChanged];
        [_headerView addSubview:self.codeAgainTextField];
        //下面横线
        UIView * codeAgainBottomLineView = [[UIView alloc] initWithFrame:CGRectMake(codeImg.left, codeAgainImg.bottom + 8/WIDTH_6_SCALE, SCREEN_WIDTH - codeImgX*2, 1/WIDTH_6_SCALE)];
        codeAgainBottomLineView.backgroundColor = getColor(grayColor);
        [_headerView addSubview:codeAgainBottomLineView];
        //礼物图案
        UIImageView * giftImg = [[UIImageView alloc] initWithFrame:CGRectMake(phoneImg.left, codeAgainBottomLineView.bottom + 44/WIDTH_6_SCALE, 16/WIDTH_6_SCALE, 17.5/WIDTH_6_SCALE)];
        giftImg.centerX = phoneImg.centerX;
        giftImg.image = [UIImage imageNamed:@"invateCode"];
        [_headerView addSubview:giftImg];
        //最下面输入框
        self.inviteTextField = [[UITextField alloc] initWithFrame:CGRectMake(self.phoneTextField.left, 0, self.phoneTextField.width, self.phoneTextField.height)];
        self.inviteTextField.centerY = giftImg.centerY;
        self.inviteTextField.delegate = self;
        self.inviteTextField.font = DEF_FontSize_12;
        self.inviteTextField.placeholder = @"请输入邀请码(可不填)";
        [_headerView addSubview:self.inviteTextField];
        //最下面横线
        UIView * downLineView = [[UIView alloc] initWithFrame:CGRectMake(topLineView.left, giftImg.bottom + 8/WIDTH_6_SCALE, topLineView.width, topLineView.height)];
        downLineView.backgroundColor = getColor(grayColor);
        [_headerView addSubview:downLineView];
        //关联账号
        int loginBtnX = 48/WIDTH_6_SCALE;
        UIButton * relatedBtn = [[UIButton alloc] initWithFrame:CGRectMake(loginBtnX, downLineView.bottom + 36/WIDTH_6_SCALE, SCREEN_WIDTH - loginBtnX*2, 37/WIDTH_6_SCALE)];
        [relatedBtn setTitle:@"关联账号" forState:UIControlStateNormal];
        [relatedBtn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
        relatedBtn.titleLabel.font = DEF_FontSize_14;
        [relatedBtn addTarget:self action:@selector(relatedBtnClick:) forControlEvents:UIControlEventTouchUpInside];
        [self button:relatedBtn withBGColor:getColor(@"3675bd") withLayerBorderColor:nil withLayerBorderWith:0 withCornerRadius:6 withMasksToBounds:YES withViwe:_headerView];
        //隐私规则和服务条款
        UILabel * frontLab = [[UILabel alloc] init];
        [self label:frontLab withFont:DEF_FontSize_10 withText:@"注册福乐猪即为阅读和默认" withTextColor:getColor(@"cbcbcb") withTextAlignment:NSTextAlignmentRight withView:_headerView];
        //隐私规则
        UIButton * privacyBtn = [[UIButton alloc] init];
        [self button:privacyBtn withBGColor:[UIColor clearColor] withLayerBorderColor:nil withLayerBorderWith:0 withCornerRadius:0 withMasksToBounds:NO withViwe:self.view];
        privacyBtn.titleLabel.font = DEF_FontSize_10;
        NSMutableAttributedString *privacyTitle = [[NSMutableAttributedString alloc] initWithString:@"隐私规则"];
        NSRange privacyTitleRange = {0,[privacyTitle length]};
        [privacyTitle addAttribute:NSUnderlineStyleAttributeName value:[NSNumber numberWithInteger:NSUnderlineStyleSingle] range:privacyTitleRange];
        [privacyTitle addAttribute:NSForegroundColorAttributeName value:getColor(@"cbcbcb") range:privacyTitleRange];
        [privacyBtn setAttributedTitle:privacyTitle
                              forState:UIControlStateNormal];
        [privacyBtn addTarget:self action:@selector(privacyBtnClick:) forControlEvents:UIControlEventTouchUpInside];
        [_headerView addSubview:privacyBtn];
        //和
        UILabel * andLab = [[UILabel alloc] init];
        [self label:andLab withFont:DEF_FontSize_10 withText:@"和" withTextColor:getColor(@"cbcbcb") withTextAlignment:NSTextAlignmentCenter withView:_headerView];
        //服务条款
        UIButton * serveBtn = [[UIButton alloc] init];
        [self button:serveBtn withBGColor:[UIColor clearColor] withLayerBorderColor:nil withLayerBorderWith:0 withCornerRadius:0 withMasksToBounds:NO withViwe:self.view];
        serveBtn.titleLabel.font = DEF_FontSize_10;
        [serveBtn addTarget:self action:@selector(serveBtnClick:) forControlEvents:UIControlEventTouchUpInside];
        NSMutableAttributedString *serveTitle = [[NSMutableAttributedString alloc] initWithString:@"服务条款"];
        NSRange serveTitleRange = {0,[serveTitle length]};
        [serveTitle addAttribute:NSUnderlineStyleAttributeName value:[NSNumber numberWithInteger:NSUnderlineStyleSingle] range:serveTitleRange];
        [serveTitle addAttribute:NSForegroundColorAttributeName value:getColor(@"cbcbcb") range:serveTitleRange];
        [serveBtn setAttributedTitle:serveTitle
                            forState:UIControlStateNormal];
        [_headerView addSubview:serveBtn];

        __weak typeof (self)weakSelf = self;
        [frontLab mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(weakSelf.headerView.mas_left).mas_offset(48/WIDTH_6_SCALE);
            make.bottom.equalTo(weakSelf.headerView.mas_bottom).mas_offset(- 34/WIDTH_6_SCALE);
            make.height.mas_offset(12/WIDTH_6_SCALE);
        }];
        [privacyBtn mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(frontLab.mas_right).mas_offset(2/WIDTH_6_SCALE);
            make.top.height.equalTo(frontLab);
        }];
        [andLab mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(privacyBtn.mas_right).mas_offset(2/WIDTH_6_SCALE);
            make.top.height.equalTo(frontLab);
        }];
        [serveBtn mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(andLab.mas_right).mas_offset(2/WIDTH_6_SCALE);
            make.top.height.equalTo(frontLab);
        }];
        _headerView.frame = CGRectMake(0, 0, SCREEN_WIDTH, relatedBtn.bottom + 138/WIDTH_6_SCALE);
    }return _headerView;
}
#pragma mark - action
- (void)getVerificationCodeBtnClick:(UIButton *)sender{
    NSLog(@"获取验证码");
    if ([self valiMobile:self.phoneTextField.text]) {
        self.telNumStr = self.phoneTextField.text;
        //获取验证码
        [self sendMessageCode];
        //初始化定时器
        _timmer = [NSTimer scheduledTimerWithTimeInterval:1 target:self selector:@selector(test:) userInfo:nil repeats:YES];
    }else{
        [self.view makeToast:@"请正确填写手机号码" duration:1 position:CSToastPositionCenter style:nil];
        return;
    }
}
- (void)test:(NSTimer *)timmer{
    NSString *str = [NSString stringWithFormat:@"%d后重试",i];
    self.getVerificationCodeBtn.titleLabel.text = str;
    self.getVerificationCodeBtn.userInteractionEnabled = NO;
    i--;
    if (i == -1) {
        [timmer invalidate];
        self.getVerificationCodeBtn.titleLabel.text = @"获取验证码";
        self.getVerificationCodeBtn.userInteractionEnabled = YES;
        i = 59;
    }
}
- (void)relatedBtnClick:(UIButton *)sender{
    NSLog(@"关联账号");
    if (self.phoneTextField.text.length < 11) {
        [self.view makeToast:@"请正确填写手机号码" duration:1 position:CSToastPositionCenter style:nil];
        return;
    }
    if (![self valiMobile:self.phoneTextField.text]) {
        [self.view makeToast:@"请正确填写手机号码" duration:1 position:CSToastPositionCenter style:nil];
        return;
    }
    if ([self.codeTextField.text isEqualToString:@""] || [self.codeTextField.text length] == 0 || self.codeTextField.text == nil) {
        [self.view makeToast:@"请填写密码" duration:1 position:CSToastPositionCenter style:nil];
        return;
    }
    if ([self.codeAgainTextField.text isEqualToString:@""] || [self.codeAgainTextField.text length] == 0 || self.codeAgainTextField.text == nil) {
        [self.view makeToast:@"请确认密码" duration:1 position:CSToastPositionCenter style:nil];
        return;
    }
    if (![self.codeTextField.text isEqualToString:self.codeAgainTextField.text]) {
        [self.view makeToast:@"两次填写密码不同" duration:1 position:CSToastPositionCenter style:nil];
        return;
    }
    [self tiePhoneNum];//接口
}
- (void)privacyBtnClick:(UIButton *)sender{
    NSLog(@"隐私规则");
}
- (void)serveBtnClick:(UIButton *)sender{
    NSLog(@"服务条款");
}
- (void)textFieldDidChange :(UITextField *)theTextField{
    if (self.phoneTextField) {
        if (self.phoneTextField.text.length == 11) {
            if ([self valiMobile:self.phoneTextField.text]) {
                NSLog(@"%@", self.phoneTextField.text);
            }else{
                [self.view makeToast:@"请正确填写手机号码" duration:1 position:CSToastPositionTop style:nil];
                return;
            }
        }
        if (self.phoneTextField.text.length > 11) {
            [self.view makeToast:@"请正确填写手机号码" duration:1 position:CSToastPositionTop style:nil];
            return;
        }
    }
}
@end
